﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YJKSparseDistance.Properties;

namespace YJKSparseDistance.ModelLayer
{
	public abstract class BaseCurvePacker
	{
		public Curve ThisCurve
		{
			get
			{
				return this.m_thisCurve;
			}
			set
			{
				this.m_thisCurve = value;
			}
		}

		public bool IfCanGo
		{
			get
			{
				return this.m_ifCanGo;
			}
		}

		public bool IfFreeEnd
		{
			get
			{
				return this.m_ifFreeEnd;
			}
		}

		public bool IfCanIntersection
		{
			get
			{
				return this.m_bIfCanIntersection;
			}
		}

		public bool IfDoorFreeEnd
		{
			get
			{
				return this.m_ifDoorFreeEnd;
			}
		}

		public XYZ MidPoint
		{
			get
			{
				return this.m_midPoint;
			}
		}

		protected BaseCurvePacker(Curve inputCurve, bool ifCanGo, bool ifFreeEnd = false, bool ifCanIntersection = false, bool ifIsDoorFreeEnd = false)
		{
			this.m_thisCurve = inputCurve;
			this.m_ifCanGo = ifCanGo;
			this.m_ifFreeEnd = ifFreeEnd;
			this.m_bIfCanIntersection = ifCanIntersection;
			this.m_ifDoorFreeEnd = ifIsDoorFreeEnd;
			this.m_midPoint = Utility.GetCurveMidPoint(this.ThisCurve);
		}

		public virtual List<Curve> GetDiscreteCurves(int discreteCount = 1)
		{
			if (0 >= discreteCount)
			{
				throw new EvacuationDistanceException(Resources.Exception_DiscreteError);
			}
			List<Curve> list = new List<Curve>();
			int num = discreteCount + 1;
			double[] array = new double[num];
			double num2 = this.m_thisCurve.GetEndParameter(1) - this.m_thisCurve.GetEndParameter(0);
			for (int i = 0; i < num; i++)
			{
				if (i == 0)
				{
					array[i] = this.m_thisCurve.GetEndParameter(0);
				}
				else if (num - 1 == i)
				{
					array[i] = this.m_thisCurve.GetEndParameter(1);
				}
				else
				{
					array[i] = (double)(i / (num - 1)) * num2 + array[0];
				}
			}
			for (int j = 0; j < num - 1; j++)
			{
				Curve curve = this.m_thisCurve.Clone();
				curve.MakeBound(array[j], array[j + 1]);
				list.Add(curve);
			}
			return list;
		}

		private Curve m_thisCurve;

		private bool m_ifCanGo;

		private bool m_ifFreeEnd;

		private bool m_bIfCanIntersection;

		private bool m_ifDoorFreeEnd;

		private XYZ m_midPoint;
	}
}
